using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace SimpleFramework
{
    [CustomEditor(typeof(UIListView), true)]
    [CanEditMultipleObjects]
    public class UIListViewEditor : Editor
    {
        UIListView m_Target;

        SerializedProperty m_Assets;
        SerializedProperty m_EnableScroll;
        SerializedProperty m_LayoutType;
        SerializedProperty m_SettingScrollRect;
        SerializedProperty m_SettingVertical;
        SerializedProperty m_SettingHorizontal;
        SerializedProperty m_SettingGrid;

        protected virtual void OnEnable()
        {
            m_Target = this.target as UIListView;

            m_Assets = serializedObject.FindProperty("m_Assets");
            m_EnableScroll = serializedObject.FindProperty("m_EnableScroll");
            m_LayoutType = serializedObject.FindProperty("m_LayoutType");
            m_SettingScrollRect = serializedObject.FindProperty("m_SettingScrollRect");
            m_SettingVertical = serializedObject.FindProperty("m_SettingVertical");
            m_SettingHorizontal = serializedObject.FindProperty("m_SettingHorizontal");
            m_SettingGrid = serializedObject.FindProperty("m_SettingGrid");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();


            DrawComSetting();
            GUILayout.Space(5);
            DrawScrollSetting();
            GUILayout.Space(5);
            DrawLayoutSetting();

            serializedObject.ApplyModifiedProperties();
        }

        void DrawComSetting()
        {
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label("List View");
            EditorGUILayout.PropertyField(m_Assets, true);
            EditorGUILayout.PropertyField(m_LayoutType, true);
            EditorGUILayout.PropertyField(m_EnableScroll, true);
            GUILayout.EndVertical();
        }

        void DrawScrollSetting()
        {
            if (!m_EnableScroll.boolValue) return;

            GUI.changed = false;
            GUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.PropertyField(m_SettingScrollRect, true);
            GUILayout.EndVertical();

            //if (GUI.changed)
            //{
            //    Debug.Log("DrawScrollView");
            //}
        }

        void DrawLayoutSetting()
        {
            GUI.changed = false;
            if (m_LayoutType.intValue == 0)
            {
                GUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.PropertyField(m_SettingVertical, true);
                GUILayout.EndVertical();
            }
            else if (m_LayoutType.intValue == 1)
            {
                GUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.PropertyField(m_SettingHorizontal, true);
                GUILayout.EndVertical();
            }
            else
            {
                GUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.PropertyField(m_SettingGrid, true);
                GUILayout.EndVertical();
            }

            //if (GUI.changed)
            //{
            //    Debug.Log("DrawLayoutSettingView");
            //}
        }
    }
}